﻿using System;
using UnityEngine;

public class OptionGameOfFieldWidth : MonoBehaviour {
	// === Unity ======================================================================================================
	public UILabel Label;
	public UIProgressBar ProgressBar;

	private void Awake() {
		if (Label == null) {
			throw new ArgumentException("Label is null");
		}

		if (ProgressBar == null) {
			throw new ArgumentException("ProgressBar is null");
		}
	}

	private void Start() {
		ProgressBar.value = (SettingsLevelModel.FieldSize.x - Constants.MIN_FIELD) / (Constants.MAX_FIELD - Constants.MIN_FIELD);
		EventDelegate.Add(ProgressBar.onChange, ProgressBarChangeCallback);
	}

	private void Update() {
		Label.text = "width: " + (int)SettingsLevelModel.FieldSize.x;
	}

	// === Private ====================================================================================================
	private void ProgressBarChangeCallback() {
		var value = (int)(UIProgressBar.current.value * (Constants.MAX_FIELD - Constants.MIN_FIELD)) + Constants.MIN_FIELD;
		SettingsLevelModel.SetFieldWidth(value);
	}
}